#-----------------------------------
# Name: Nate Richter
# Project Madlibs.py
# Period: 1
# Start Date: 9/18/2013
# Last Revision Date: 9/18/2013
# Version: 1.0.1
#----------------------------
import os

swearList = ["dumb",
             "stupid",
             "retard"]
             
bgColor = '0'
txtColor = 'F'

def getMenuOption(maxOptions):
    option = ""
    goodOption = False
    while not goodOption:
        option = raw_input("Enter a number or S or Q> ")
        option = option.upper()
        if option == 'S':
            goodOption = True
        elif option == 'Q' :
            goodOption = True
        elif option == "":
            pass
        else:
            isNum = True
            for character in option:
                if character not in "0123456789":
                    isNum = False
            if isNum:
                if int(option) <= 0:
                    isNum = False
                elif int(option) > maxOptions:
                    isNum = False
            if isNum:
                goodOption = True
            else:
                print "Please type a number!"
        if not goodOption:
            print "Invalid Choice, please try again. "
    return option

def menu():
    print "Welcome to Madlibs"
    print "Please Select an Option:"
    print " [1] Squid and Submarine Battle"
    print " [2] The Town"
    print " [3] Time Travelling Sasquatch and Dinosaur"
    print " [S] Settings"
    print " [Q] Quit"
    option = getMenuOption(3)
    return option

def getWord(prompt):
    word = ""
    goodWord = False
    while not goodWord:
        word = raw_input(prompt)
        if word.lower() not in swearList:
            goodWord = True
        else:
            print "Naughty user...please be polite!"
        if not goodWord:
            print "Please try again."
    return word
    
def getOcean(prompt):
    oceanList = ["Pacific",
                 "Atlantic",
                 "Arctic",
                 "Indian",
                 "Southern",
                 "Antarctic",]
                 
    word = ""
    goodWord = False
    while not goodWord:
        word = raw_input(prompt)
        word = word.capitalize()
        if word in oceanList:
            goodWord = True
        else:
            print "That's not an ocean"
        if not goodWord:
            print "Please try again."
    return word    

def getWon_or_Lost(prompt):
    Won_or_LostList = ["won",
                 "lost"]
                 
    word = ""
    goodWord = False
    while not goodWord:
        word = raw_input(prompt)
        if word in Won_or_LostList:
            goodWord = True
        else:
            print "Type won or lost."
        if not goodWord:
            print "Please try again."
    return word
    
def getNumber(prompt, min = "", max = ""):
        num = ""
        goodNumber = False
        while not goodNumber:
            num = raw_input(prompt)
            isNum = True
            for digit in num:
                if digit not in ".0123456789":
                    isNum = False
            if isNum:
                if min != "":
                    if float(num) < min:
                        isNum = False
                if max != "":
                    if float(num) > max:
                        isNum = False
            if isNum:
                goodNumber = True
            else:
                print "Please enter a valid number"
        return num
                    
def getColor(prompt):
        colors = ["black",
                          "blue",
                          "green",
                          "aqua",
                          "red",
                          "purple",
                          'yellow',
                          'white',
                          'gray',
                          'light blue',
                          'light green',
                          'light aqua',
                          'light red',
                          'light purple',
                          'light yellow',
                          'bright white']
        opt = ""
        goodColor = False
        while not goodColor:
                opt = raw_input(prompt)
                if opt.lower() in colors:
                        goodColor = True
        if opt == "black":
                color = '0'
        elif opt == 'blue':
                color = '1'
        elif opt == 'green':
                color = '2'
        elif opt == 'aqua':
                color = '3'
        elif opt == 'red':
                color = '4'
        elif opt == 'purple':
                color = '5'
        elif opt == 'yellow':
                color = '6'
        elif opt == 'white':
                color = '7'
        elif opt == 'gray':
                color = '8'
        elif opt == 'light blue':
                color = '9'
        elif opt == 'light green':
                color = 'A'
        elif opt == 'light aqua':
                color = 'B'
        elif opt == 'light red':
                color = 'C'
        elif opt == 'light purple':
                color = 'D'
        elif opt == 'light yellow':
                color = 'E'
        elif opt == 'bright white':
                color = 'F'
        
        return color
                                        
def story1():
    Ocean = getOcean("Enter an Ocean: ")
    Name1 = getWord("Enter the name of the submarine: ")
    Captain = getWord("Enter the captains name: ")
    color1 = getWord("Enter a Color: ")
    number1 = getNumber("Enter a number: ")
    verb1 = getWord("Enter a celebrating action, no past tense: ")
    Won_or_Lost = getWon_or_Lost("Choose and enter won or lost: ")
    story = "Deep below the surface the submarine was diving down into the "
    story += Ocean + " Ocean. "
    story += "The submarine was called the "
    story += Name1 + ". "
    story += "Its fearless captain, "
    story += Captain + " lead the crew after the giant squid. It's slimy "
    story += color1 + " tentacles started to crush the "
    story += Name1 + ". "
    story += Captain + " commanded fire all the torpedoes! "
    story += number1 + " tentacles flew off the "
    story += Name1 + " and the giant squid started to sink down. The crew started to "
    story += verb1 + " because they won the battle! As they returned to the surface the captain was still not completely certain if they had "
    story += Won_or_Lost + " the battle against the giant squid or had the the squid survived?"
    print story

def story2():
    state = getWord("Enter a state: ")
    size = getWord("Enter a size: ")
    animal = getWord("Enter an animal: ")
    verb1 = getWord("Enter an action: ")
    verb2 = getWord("Enter another action: ")
    location = getWord("Enter a location: ")
    color = getWord("Enter a color: ")
    story = "You walk into a "
    story += size + " quite town in "
    story += state + ". "
    story += "You think that something is very strange about this "
    story += size + " town in "
    story += state + ". "
    story = "Out of the corner of your eye you think you see a "
    story += animal + " running off into the local motel. You "
    story += verb1 + " after it. It turns around and trys to "
    story += verb2 + " at you! It then leaves out the back into a "
    story += location + ".  A spaceship lands flashing "
    story += color + " lights in every direction! Later that night at the local motel you try to understand what that "
    story += animal + " was doing with the spaceship, but you never really understand what happened that night."
    print story

def story3():
    name = getWord("Enter a name: ")
    time1 = getWord("Enter a time period: ")
    emotion = getWord("Enter an emotion: ")
    noise = getWord("Enter a noise: ")
    action = getWord("Enter an action: ")
    color = getWord("Enter a color: ")
    time2 = getWord("Enter a time period: ")
    story = "Sasquatch and Dinosaur were getting their time machine the "
    story += name + " ready for their next time travelling adventure! This time they were travelling to the "
    story += time1 + " ages. They both felt very "
    story += emotion + " to go to this time period. The "
    story += name + " started to shake and make "
    story += noise + " noises! Suddenly the time machine "
    story += action + " and was warping between different times. Dinosaur and Sasquatch pressed buttons franticly trying to get the time machine under control as "
    story += color + " sparks and rays shot in every direction. Sasquatch and Dinosaur made the decision to abandon the "
    story += name + ". They jumped out and started travelling through different times. They finally landed in the"
    story += time2 + " period and lived there the rest of their days."
    print story
def settings():
    txtColor = getColor("Colors to choose from are \nblack,\nblue,\ngreen,\naqua,\nred,\npurple,\nyellow,\nwhite,\ngray,\nlight blue,\nlight green,\nlight aqua,\nlight red,\nlight purple,\nlight yellow,\nbright white \nEnter Text Color: ")
    bgColor = getColor("Enter Background Color: ")
    if txtColor != bgColor:
        os.system("color " + bgColor + txtColor)
    
def run():
    choice = ""
    while choice != 'Q':
        choice = menu()
        if choice == '1':
            story1()
        elif choice == '2':
            story2()
        elif choice == '3':
            story3()
        elif choice == 'S':
            settings()
        elif choice == 'Q':
            print " Goodbye"
            os.system("color " + bgColor + txtColor)
            raw_input("Press enter to exit")
        else:
            print "Something terrible has happened...go yell at the programmer"
    
run()